package com.meilai.project.dto.business.intentionScheme;

import com.meilai.project.entity.media.MediaPoint;
import com.meilai.project.entity.media.MediaPointExt;
import com.meilai.project.vo.business.media.MediaPointExtVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Objects;

/**
 * @author xchen
 * @since 2022-03-21
 */
@Data
@ApiModel
public class MediaPointSimpleVO {

    @ApiModelProperty("点位id")
    private Long id;

    @ApiModelProperty("AB面时，与之匹配的media_id")
    private Long pair_media_id;

    @ApiModelProperty(value = "media_type_spec_id")
    private Long media_type_spec_id;

    @ApiModelProperty(value = "编号")
    private String code;

    @ApiModelProperty(value = "项目id", example = "1")
    private Long building_area_id;

    @ApiModelProperty(value = "媒体类型id", example = "1")
    private Long media_type_id;

    @ApiModelProperty(value = "AB面id", example = "1")
    private Long ab_type_id;

    @ApiModelProperty(value = "楼号")
    private String building_number;

    @ApiModelProperty(value = "单元号")
    private String unit_number;

    @ApiModelProperty(value = "层数")
    private String floor;

    @ApiModelProperty(value = "门号")
    private String door_number;

    @ApiModelProperty("media_type_spec_price_id")
    private Long media_type_spec_price_id;

    @ApiModelProperty("full_detail")
    private String full_detail;

    // todo 市场单新增
    @ApiModelProperty("媒体类型名称")
    private String media_type;

    // todo 市场单新增
    @ApiModelProperty("规格 对内宽*高")
    private String media_type_spec;

    // todo 市场单新增
    @ApiModelProperty("材质类型名称")
    private String media_pic_type;

    // todo 市场单新增
    @ApiModelProperty("宽（对内）")
    private String size_width;

    // todo 市场单新增
    @ApiModelProperty("高（对内）")
    private String size_height;

    // todo 市场单新增
    @ApiModelProperty("材质类型ID")
    private Long media_pic_type_id;

    public static MediaPointSimpleVO parseFrom(MediaPoint p) {
        MediaPointSimpleVO mediaPointSimpleVO = new MediaPointSimpleVO();
        mediaPointSimpleVO.setId(p.getId());
        mediaPointSimpleVO.setCode(p.getCode());
        mediaPointSimpleVO.setMedia_type_spec_id(p.getMedia_type_spec_id());
        mediaPointSimpleVO.setBuilding_area_id(p.getBuilding_area_id());
        mediaPointSimpleVO.setMedia_type_id(p.getMedia_type_id());
        mediaPointSimpleVO.setAb_type_id(p.getAb_type_id());
        mediaPointSimpleVO.setBuilding_number(null == p.getBuilding_number() ? "" : p.getBuilding_number());
        mediaPointSimpleVO.setUnit_number(p.getUnit_number());
        mediaPointSimpleVO.setFloor(p.getFloor());
        mediaPointSimpleVO.setDoor_number(p.getDoor_number());
        if (p instanceof MediaPointExt) {
            mediaPointSimpleVO.setMedia_type_spec_price_id(((MediaPointExt) p).getMedia_type_spec_price_id());
            mediaPointSimpleVO.setFull_detail(((MediaPointExt) p).getFull_detail());
        }
        // todo 市场单新增
        if (p instanceof MediaPointExtVO) {
            mediaPointSimpleVO.setSize_width(p.getSize_width_inside());
            mediaPointSimpleVO.setSize_height(p.getSize_height_inside());
            mediaPointSimpleVO.setMedia_type_spec(p.getSize_width_inside() + "*" + p.getSize_height_inside());
            mediaPointSimpleVO.setMedia_type(((MediaPointExtVO) p).getMedia_type());
            mediaPointSimpleVO.setMedia_pic_type(((MediaPointExtVO) p).getMedia_pic_type());
            mediaPointSimpleVO.setMedia_pic_type_id(p.getPic_type_id());
        }
        return mediaPointSimpleVO;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof MediaPointSimpleVO)) return false;
        return this.getId().equals(((MediaPointSimpleVO) o).getId());
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, pair_media_id, code, building_area_id, media_type_id, ab_type_id, building_number, unit_number, floor, door_number);
    }

}
